<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="include/peizhi.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="${ctx}">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
        
        <title>后台管理中心</title> 
		<link rel="stylesheet" href="${ctx}/css/pintuer.css" /> 
		<link rel="stylesheet" href="${ctx}/css/admin.css" /> 
        <script type="text/javascript" src="${ctx}/js/jquery-1.9.1.min.js"></script>
        <script type="text/javascript" src="${ctx}/js/pagehoutai.js?v=20170530"></script>
    </head>
  	<body style="background-color:#f2f9fd;"> 
	  <jsp:include page="include/header.jsp" flush="true"/>
  <div class="admin"> 
	  <div class="panel admin-panel">
	    <div class="panel-head"><strong class="icon-reorder"> 留言管理</strong></div>
	    <div class="padding border-bottom">
	      <ul class="search">
	        <li>
	          <button type="button"  class="button border-green" id="checkall"><input type='checkbox' id='allSelect'> 全选</button>
	          <button type="submit" class="button border-red" onclick='deletebook()'><span class="icon-trash-o"></span> 批量删除</button>
	        </li>
	      </ul>
	    </div>
	    <form id='deletebook'>
		    <table id='pagehtml' class="table table-hover text-center">
		    </table>
	    </form>
	    <form id="pageForm" action="${ctx}/book/getList">
			<input type="hidden" name="pageNo" id="pageNo" value="0" /> 
			<input type="hidden" name="pageSize" id="pageSize" value="10" /> 
			<input id='lastPage' type="hidden">
		</form>
	  </div>
	<script type="text/javascript">
	
	function del(id){
		if(confirm("您确定要删除吗?")){
			$().attr();
			alert(id);
		}
	}
	
	$("#checkall").click(function(){ 
	  $("input[name='id[]']").each(function(){
		  if (this.checked) {
			  this.checked = false;
		  }
		  else {
			  this.checked = true;
		  }
	  });
	});
	
	function DelSelect(){
		var Checkbox=false;
		 $("input[name='id[]']").each(function(){
		  if (this.checked==true) {		
			Checkbox=true;	
		  }
		});
		if (Checkbox){
			var t=confirm("您确认要删除选中的内容吗？");
			if (t==false) return false; 		
		}
		else{
			alert("请选择您要删除的内容!");
			return false;
		}
	}
	//分页
	page(1,$("#pageSize").val());
 	var listhead='<tr>'+
	      '<th width="120">ID</th>'+
	      '<th>姓名</th>'+
	      '<th>电话</th>'+
	     ' <th>邮箱</th>'+
	     ' <th>地址</th>'+
	     '<th width="25%">内容</th>'+
	     ' <th width="120">留言时间</th>'+
	     ' <th>操作</th>'+
	    	'</tr>';
	    	/*<tr>
	          <td><input type="checkbox" name="id[]" value="1" />
	            1</td>
	          <td>神夜</td>
	          <td>13420925611</td>
	          <td>564379992@qq.com</td>  
	           <td>深圳市民治街道</td>         
	          <td>这是一套后台UI，喜欢的朋友请多多支持谢谢。</td>
	          <td>2016-07-01</td>
	          <td><div class="button-group"> <a class="button border-red" href="javascript:void(0)" onclick="return del(1)"><span class="icon-trash-o"></span> 删除</a> </div></td>
	        </tr>
	      <tr>
	    	*/
	var listhtml = "<tr>";
	 	listhtml = listhtml + "<td><input type='checkbox' id='{9}del' class='sequence' name='customerMessage[{10}].ids' value='{0}'/>{1}</td>";
	    listhtml = listhtml + "<td>{2}</td>";     
	    listhtml = listhtml + "<th>{3}</th>";
	    listhtml = listhtml + "<td>{4}</td>";
	    listhtml = listhtml + "<td>{5}</td> ";
	    listhtml = listhtml + "<td>{6}</td>";
	    listhtml = listhtml + "<td>{7}</td>";
	    listhtml = listhtml + "<td><div class='button-group'> <a class='button border-red' href='javascript:void(0)' onclick='return deletebook({8})'><span class='icon-trash-o'></span> 删除</a> </div></td>";
	 listhtml = listhtml + "</tr>";
	 function pageAppend(data){
	 	data.createdate = formatDate(data.createdate,'0');
		return listhtml.replace('{0}',data.id)
		.replace('{1}',data.ids)
		.replace('{2}',data.name)
		.replace('{3}',data.mobile)
		.replace('{4}',data.email)
		.replace('{5}',data.alladdress)
		.replace('{6}',data.contents)
		.replace('{7}',data.createdate)
		.replace('{8}',data.id)
		.replace('{9}',data.id)
		.replace('{10}',data.ids);
	}
	function deletebook(id){
		var ids;
		if(id!='' && id!=null){
			ids='customerMessage[0].ids='+id;
		}else{
			ids = $("#deletebook").serialize();
		}
		if(confirm("您确定要删除吗?")){
			$.ajax({
				url:"${ctx}/book/delete",
				data:ids,
				type:"post",
				success:function(data){
					if(data=='0'){
						alert("删除成功");
						page($('#pageNo').val(),3);
					}else{
						alert("删除失败");
					}
				}
			});
			
		}
	}
	
	//判断单选框是否被选中
	//document.getElementById("checkboxID").checked
	$("#allSelect").click(function(){
		var fir = $(".sequence");
		if(document.getElementById("allSelect").checked){
			//选中
			//$(".sequence").attr("checked","true");
			//alert("aaaaaaaaa");
			for(var i=0;i<fir.length;i++){
			    fir[i].checked = true;
			}
		}else{
			for(var i=0;i<fir.length;i++){
			    fir[i].checked = false;
			}
			//$(".sequence").attr("checked","false");
		}
	});
	</script>
  </div> 
 </body>
</html>